<!-- 跟投分配规则 -->
<template>
	<div >
	    <el-form :inline="true" :model="ruleForm" class="demo-form-inline">
	        <el-form-item label="规则名称：">
	            <el-input placeholder="请输入规则名称" v-model.trim="ruleForm.name" maxlength="20"></el-input>
	        </el-form-item>
	        <el-form-item>
	            <el-button type="primary" @click="searchList" id="monitorEnter">查询</el-button>
	            <el-button type="primary"  @click="add">新增</el-button>
	         </el-form-item>
	    </el-form>
	
	    <el-table :data="tableData" border>
	        <el-table-column type="index" label="序号" width="50" align="center"></el-table-column>
	        <el-table-column label="规则名称" prop="name" align="center"></el-table-column>
	        <el-table-column label="定向分配占比(%）" prop="directionalProportion"  align="center"></el-table-column>
	        <el-table-column label="募集分配占比(%）" prop="raiseProportion" align="center"></el-table-column>
	        <el-table-column label="版本号" prop="version" align="center"></el-table-column>
	        <el-table-column label="更新人" prop="updateUsername" align="center"></el-table-column>
	        <el-table-column label="更新时间" prop="updateTime" align="center">
	        </el-table-column>
	        <el-table-column label="状态" prop="status" align="center">
	        	<template slot-scope="scope">
	        		{{scope.row.status==0?'未启用':'已启用'}}
	        	</template>
	        </el-table-column>
	        <el-table-column label="操作" align="center">
	             <template slot-scope="scope">
	                <el-button type="text" v-if="scope.row.status == 0" @click="operation('open',scope.row)">启用</el-button>
	                <el-button type="text" v-if="scope.row.status == 1" @click="operation('recall',scope.row)">撤回</el-button>
	                <el-button type="text" :disabled="scope.row.status == 1 && scope.row.openFlag == 1" @click="operation('edit',scope.row)">编辑</el-button>
	                <el-button type="text" @click="operation('info',scope.row)">详情</el-button>
	               <el-button type="text" :disabled="scope.row.status == 1 || scope.row.openFlag == 1" @click="operation('del',scope.row)">删除</el-button>
	             </template> 
	        </el-table-column>
	    </el-table>

	    <div class="pagebar">
	        <el-pagination
	                background
	                layout="total, sizes, prev, pager, next"
	                :current-page.sync="ruleForm.pageNum"
	                :page-sizes="[10, 20, 30, 40]"
	                :page-size="ruleForm.pageSize"
	                @size-change="handleSizeChange"
	                @current-change="handleCurrentChange"
	                :total="total">
	        </el-pagination>
	    </div>
	</div>
</template>
<script>
	import api from '@/api/apiPath'
	export default {
		name:'investmentDistributionRule',
		title:'跟投分配规则',
	    data() {
	        return {
	            ruleForm: {
	                name: undefined,
	                pageNum: 1,
	                pageSize: 10,
	            },
	            total: 0,
	            tableData: []
	        }
	    },
	    created() {
	        this.getlist()
	    },
	    activated(){
			this.searchList()
	    },
	    methods: {
	    	handleCurrentChange() {
	    	    this.getlist()
	    	},
	    	handleSizeChange(val) {
	    	    this.ruleForm.pageSize = val
	    	    this.getlist();
	    	},
	    	searchList(){
	    	    this.ruleForm.pageNum = 1
	    	    this.getlist()
	    	},
	    	add(){
	    		this.$router.push({path:'/investmentRuleAdd',query:{pageType:'add'}})
	    	},
	    	getlist(){
	    		this.axios.post(api.DISTRIBUTIONRULELIST,this.ruleForm).then(res=>{
	    			if (res.data.code==200) {
	    				this.tableData = res.data.data.list
	    				this.total = res.data.data.total
	    			}
	    		})
	    	},
	    	operation(type,val){
	    		// console.log(val)
	    		if (type == 'info') {
	    			this.$router.push({path:'/investmentRuleInfo',query:{id:val.id}})
	    		}else if(type == 'open'){
					this.$confirm('确定要启用吗?', '提示', {
					  confirmButtonText: '确定',
					  cancelButtonText: '取消',
					  type: 'warning',
					  center: true
					}).then(() => {
						this.axios.get(api.DISTRIBUTIONOPAN+val.id).then(res=>{
							if (res.data.code == 200) {
								this.$message({
								  type: 'success',
								  message: '启用成功'
								});   
								this.getlist()
							}
						})
					}).catch(() => {
						  this.$message({
						    type: 'info',
						    message: '已取消'
						  });          
					});
	    		}else if(type == 'recall'){
	    			this.$confirm('确定要撤回吗?', '提示', {
	    			  confirmButtonText: '确定',
	    			  cancelButtonText: '取消',
	    			  type: 'warning',
	    			  center: true
	    			}).then(() => {
	    				this.axios.get(api.DISTRIBUTIONRECALL+val.id).then(res=>{
	    					if (res.data.code == 200) {
	    						this.$message({
	    						  type: 'success',
	    						  message: '撤回成功'
	    						});   
	    						this.getlist()
	    					}
	    				})	
	    			}).catch(() => {
	    				  this.$message({
	    				    type: 'info',
	    				    message: '已取消'
	    				  });          
	    			});

	    		}else if(type == 'edit'){
	    			this.$router.push({path:'/investmentRuleAdd',query:{pageType:'edit',id:val.id}})
	    		}else if(type == 'del'){
	    			this.$confirm('确定要删除吗?', '提示', {
	    			  confirmButtonText: '确定',
	    			  cancelButtonText: '取消',
	    			  type: 'warning',
	    			  center: true
	    			}).then(() => {
	    				this.axios.get(api.DISTRIBUTTIONDEL+val.id).then(res=>{
	    					if (res.data.code == 200) {
	    						this.$message({
	    						  type: 'success',
	    						  message: '删除成功'
	    						});   
	    						this.getlist()
	    					}
	    				})	
	    			}).catch(() => {
	    				  this.$message({
	    				    type: 'info',
	    				    message: '已取消'
	    				  });          
	    			});
	    		}
	    	}
	    }
	}

</script>

<style lang="stylus">

</style>